package cn.backpackerxl.easyJDBC.util;

import java.util.ArrayList;
import java.util.List;

public class JSONRuleEngine {
    private static final List<JSONParseRule> jsonParseRules = new ArrayList<>();

    static {
        jsonParseRules.add(new AddIntRule());
        jsonParseRules.add(new AddLongRule());
        jsonParseRules.add(new AddStringRule());
        jsonParseRules.add(new AddDoubleRule());
        jsonParseRules.add(new AddBooleanRule());
        jsonParseRules.add(new AddByteRule());
        jsonParseRules.add(new AddCharRule());
        jsonParseRules.add(new AddShortRule());
        jsonParseRules.add(new AddDateRule());
        jsonParseRules.add(new AddFloatRule());
        jsonParseRules.add(new AddObjectRule());
    }

    public void process(JSONExpression jsonExpression) {
        jsonParseRules.stream().filter(rs -> rs.evaluate(jsonExpression)).findFirst().orElseThrow(() -> new IllegalArgumentException("JSONExpression does not matches any JSONParseRule"));
    }
}
